home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
050
/
pulldwn.arc
/
PULLDOWN.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-01-24
|
11KB
|
313 lines
{$I c:\turbo\qwik\qwik21.inc}
{$I c:\turbo\qwik\window31.inc}
(*************************************************************************)
(* THIS PROGRAM ILLUSTRATES THE USE OF PULLDOWN MENUS. IT USES BOTH *)
(* QWIK21 AND WINDOW30 ROUTINES FOR ALL OF THE FAST SCREEN WRITING. *)
(* THIS PROGRAM WAS WRITTEN BY ART HILL AND BROUGHT OUT UNDER THE *)
(* TEAMWARE CONCEPT. SEE THE ACCOMPANYING DOCUMENTATION. *)
(*************************************************************************)
(* PULLDOWN.INC *)
(* Version 1.0 Copyright 1986 by Art Hill *)
(* Released under the TEAMWARE concept *)
Type
{EACH PULLDOWN MENU IS REPRESENTED BY ONE OF THE FOLLOWING RECORDS}
{THE ARRAY HOLDS THE "TITLE" OF THE MENU IN POSITION 0 AND THE }
{INDIVIDUAL SELECTIONS IN POSITIONS 1..15. NUMSUBS REFERS TO THE }
{NUMBER OF CHOICES FOR THAT PULLDOWN MENU AND HILITE REFERS TO }
{WHICH ONE IS CURRENTLY CHOSEN OR "SET"}
menus=Record
txt:Array[0..15] Of String[20];
numsubs:Byte;
hilite:1..15;
End;
choice=Array[1..8] Of menus;
keyvalues=Record
chval:Char;
ascval:0..255;
scanval:0..255;
End;
chrset=Set Of Char;
Var
j,oldcursor,normattrib:Integer;
extkey:Boolean;
tempstr:str80;
bk_color,fg_color:Integer;
st_background,esc,null,rspchr,ret:Char;
lastkey:keyvalues;
f1key,f2key,f3key,f4key,f5key,f6key,f7key,f8key,
f9key,f10key,pgup,pgdn,homekey,endkey,cursorup,cursordn,
cursorlf,cursorrt,inskey,delkey,shtabkey,tabkey,backsp:Char;
errnum:Integer;
trash:Integer;
tab:Char;
Function roll(curval:Integer;up:Boolean;min,max:Integer):Integer;
{INCREMENTS A NUMBER UP OR DOWN, ROLLING AROUND MINIMUM OR MAXIMUM}
Begin
If up Then
If curval<max Then
curval:=curval+1
Else curval:=min
Else
If curval>min Then
curval:=curval-1
Else curval:=max;
roll:=curval;
End;
Procedure getkb(Var ch:Char;Var ascii,scan:Byte);
Type regpack=Record
ax,bx,cx,dx,bp,si,ds,es,flags:Integer;
End;
Var reg:regpack;
Begin
reg.ax:=0;
Intr($16,reg);
ascii:=Lo(reg.ax);
scan:=Hi(reg.ax);
ch:=Char(ascii);
With lastkey Do
Begin
ascval:=ascii;
scanval:=scan;
If scanval>58 Then
Begin
ascval:=scanval+100;{adjust ascii value for extended codes
to putthem above 128}
extkey:=True;
End;
chval:=Char(ascval);
End;
End;
Function getkey(Var ch:Char;valid:chrset;shiftlock:Boolean):Char;
Var
ok:Boolean;
ascii,scan:Byte;
Begin
{ GETKEY }
Repeat
extkey:=False;
getkb(ch,ascii,scan);
ch:=lastkey.chval;
If (shiftlock) And (ch In ['a'..'z']) Then
ch:=Chr(Ord(ch)-32);
ok:=ch In valid;
If Not ok Then
Write(#7);
Until ok;
getkey:=ch;
End;{OF GETKEY}
Function attribute(foreground,background:Byte):Byte;
{-translates foreground and background colors into video attributes.
"and 127" masks out the blink bit. add 128 to the result to set it.}
Begin
attribute:=((background Shl 4)+foreground) And 127;
End;
Procedure setborder(color:Byte);
Begin
Port[$03d9]:=color;
End;
Procedure pulldown_menus(Var choices:choice;
no_of_items,defaultitem,col,row:Integer;
Var at_which:Integer;Var tchar:Char);
Var
c,trash,next,previous:Integer;
colstart:Array[1..8] Of Integer;
keytyped:Char;
firstletters:Array[1..8] Of Char;
validletters:Set Of Char;
match:Boolean;
Procedure showpulldown(whichone:Byte);
Begin
makewindow(row+1,colstart[whichone],choices[whichone].numsubs+2,
17,15,1,7,1,solid);
With choices[whichone] Do
Begin
For trash:=1 To numsubs Do
qwritev(row+1+trash,colstart[whichone]+2,-1,txt[trash]);
End;
With choices[whichone] Do
qattr(row+1+hilite,colstart[whichone]+1,1,15,112);
End;
Begin
cursorchange(8192,oldcursor);
validletters:=[];
colstart[1]:=col;
For trash:=2 To no_of_items Do
Begin
colstart[trash]:=
(colstart[trash-1]+3+Length(choices[trash-1].txt[0]));
End;
For trash:=1 To no_of_items Do
Begin
firstletters[trash]:=choices[trash].txt[0][1];
validletters:=validletters+[firstletters[trash]];
qwritev(row,colstart[trash],normattrib,choices[trash].txt[0]);
End;
qwritev(row,colstart[defaultitem],attribute(0,7),choices[
defaultitem].txt[0]);
showpulldown(defaultitem);
at_which:=defaultitem;
While Not(getkey(keytyped,[Chr(13),Chr(32),f10key,Chr(27),
cursorrt,pgdn,pgup,homekey,cursorup,cursordn,cursorlf,
f1key]+validletters,True) In
[Chr(13),Chr(27),Chr(32),f10key,pgdn,pgup,homekey,f1key]) Do
Begin
If (at_which<no_of_items) Then
Begin
next:=Succ(at_which);
End
Else
next:=1;
If at_which>1 Then
Begin
previous:=Pred(at_which)
End
Else
previous:=no_of_items;
c:=1;
match:=False;
If keytyped In validletters Then
Repeat
If keytyped=firstletters[c] Then
Begin
qwritev(row,colstart[at_which],attribute(fg_color,
bk_color),
choices[at_which].txt[0]);
at_which:=c;
qwritev(row,colstart[at_which],attribute(0,7),
choices[
at_which].txt[0]);
match:=True;
End;
c:=c+1;
Until match=True
Else Case keytyped Of
#175:Begin
qwritev(row,colstart[at_which],attribute(fg_color,
bk_color),
choices[at_which].txt[0]);
qwritev(row,colstart[previous],attribute(0,7),
choices[previous].txt[0]);
at_which:=previous;
removewindow;
showpulldown(at_which);
End;
#177:Begin
qwritev(row,colstart[at_which],attribute(fg_color,
bk_color),
choices[at_which].txt[0]);
qwritev(row,colstart[next],attribute(0,7),choices[
next].txt[0]);
at_which:=next;
removewindow;
showpulldown(at_which);
End;
#172:With choices[at_which] Do
Begin
qattr(row+1+hilite,colstart[at_which]+1,1,15,
normattrib);
hilite:=roll(hilite,False,1,numsubs);
qattr(row+1+hilite,colstart[at_which]+1,1,15,112);
End;
#180:With choices[at_which] Do
Begin
qattr(row+1+hilite,colstart[at_which]+1,1,15,
normattrib);
hilite:=roll(hilite,True,1,numsubs);
qattr(row+1+hilite,colstart[at_which]+1,1,15,112);
End;
End;{OF CASE}
End;{OF WHILE LOOP}
tchar:=keytyped;
cursorchange(oldcursor,trash);
removewindow;
End;{OF PROCEDURE HORIZ_WHICHITEM }
Procedure misc_init;
Begin{ MISC INITIALIZATION }
trash:=0;
esc:=Chr(27);
null:=Chr(0);
ret:=Chr(13);
f1key:=Chr(159);
f2key:=Chr(160);
f3key:=Chr(161);
f4key:=Chr(162);
f5key:=Chr(163);
f6key:=Chr(164);
f7key:=Chr(165);
f8key:=Chr(166);
f9key:=Chr(167);
f10key:=Chr(168);
cursorlf:=Chr(175);
cursorrt:=Chr(177);
cursorup:=Chr(172);
cursordn:=Chr(180);
homekey:=Chr(171);
endkey:=Chr(179);
pgup:=Chr(173);
pgdn:=Chr(181);
inskey:=Chr(182);
delkey:=Chr(183);
tabkey:=Chr(9);
tab:=Chr(9);
shtabkey:=Chr(15);
backsp:=Chr(8);
bk_color:=1;
fg_color:=15;
TextColor(fg_color);
TextBackground(bk_color);
qinit;
normattrib:=attribute(fg_color,bk_color);
End;{ OF INITIALIZATION }
(* END OF PULLDOWN.INC *)
Var picks:choice;
which:Integer;
tchar:Char;
Begin
qinit;
initwindow(15,1);
misc_init;
picks[1].txt[0]:='files';
picks[2].txt[0]:='printing';
picks[3].txt[0]:='parameters';
picks[4].txt[0]:='set up';
picks[5].txt[0]:='other';
picks[6].txt[0]:='defaults';
picks[7].txt[0]:='quit';
For trash:=1 To 7 Do
picks[trash].numsubs:=trash+3;
For trash:=1 To 7 Do
picks[trash].hilite:=trash+1;
picks[1].numsubs:=10;
For j:=1 To 7 Do
For trash:=1 To 10 Do
Begin
Str(trash,tempstr);
picks[j].txt[trash]:='choice '+tempstr;
End;
qfill(1,1,25,80,normattrib,' ');
which:=1;
Repeat
pulldown_menus(picks,7,which,1,1,which,tchar);
qfill(22,1,1,80,-1,' ');
gotorc(22,5);
Write('you chose ',picks[which].hilite,' from menu ',which,'(',
picks[which].txt[0],')');
Until which=7;
End.